NormalizedLevenshtein

class NormalizedLevenshtein(insertionWeight: Double = Constants.DEFAULT_WEIGHT, deletionWeight: Double = Constants.DEFAULT_WEIGHT, substitutionWeight: Double = Constants.DEFAULT_WEIGHT) : MetricStringDistance, NormalizedStringDistance, NormalizedStringSimilarity(source)

Implements a normalized metric based the Levenshtein distance (Yujian & Bo, 2007).

The normalized Levenshtein distance between Strings \(X\) and \(Y\) is: \(\frac{2 \times distance_{levenshtein}(X, Y)}{w_d \lvert X \rvert + w_i \lvert Y \rvert + distance_{levenshtein}(X, Y)}\).

The similarity is computed as \(1 - distance(X, Y)\).

References

Yujian, L., & Bo, L. (2007-06). A normalized levenshtein distance metric. IEEE Transactions on Pattern Analysis and Machine Intelligence, 29(6), 1091-1095. https://doi.org/10.1109/tpami.2007.1078[sci-hub]

Author

solonovamax

Parameters

insertionWeight

The weight of an insertion. Represented as \(w_i\). Must be in the range \([0, 1 \times 10^{10} ]\).

deletionWeight

The weight of a deletion. Represented as \(w_d\). Must be in the range \([0, 1 \times 10^{10} ]\).

substitutionWeight

The weight of a substitution. Represented as \(w_s\). Must be in the range \([0, 1 \times 10^{10} ]\).

See also

Constructors

Link copied to clipboard
constructor(insertionWeight: Double = Constants.DEFAULT_WEIGHT, deletionWeight: Double = Constants.DEFAULT_WEIGHT, substitutionWeight: Double = Constants.DEFAULT_WEIGHT)

Functions

Link copied to clipboard
open override fun distance(s1: String, s2: String): Double

Compute and return the metric distance.

Link copied to clipboard
open override fun similarity(s1: String, s2: String): Double

Computes the similarity of two strings. The similarity will be normalized using the number of operations that are performed.